package com.wangs.case03_16110100624;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

    private Button btn_login;
    private EditText uname,pword;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn_login =findViewById(R.id.btn_login);
//        ACTIVITY和控件形成映射
        uname = findViewById(R.id.et_username);
        pword =findViewById(R.id.et_password);
//        加事件onclick，给控件加内部setclick，定义通用事件多个控件一起用setonclick
//        给控件加内部setclick，创建对象，new一个内部类
        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                获取控件值
//                打开新activity
                Intent intent = new Intent(MainActivity.this,WelcomeActivity.class);
//                传参
                intent.putExtra("username",uname.getText().toString());
                intent.putExtra("password",pword.getText().toString());
//                启动activity,,,,
                startActivity(intent);
//                启动方法二startActivityForResult();
            }
        });
    }
}
